<!DOCTYPE html>
<html>
<head>
<title>Physics Diagram: Pulling a Boat</title>
</head>
<body>

<canvas id="physicsCanvas" width="550" height="350"></canvas>

<script>
const canvas = document.getElementById('physicsCanvas');
const ctx = canvas.getContext('2d');

// --- Style and Parameters ---
ctx.strokeStyle = 'black';
ctx.fillStyle = 'black';
ctx.lineWidth = 2;
ctx.font = '20px serif';
ctx.textAlign = 'center';

// Key coordinates and dimensions
const shoreY = 100;
const waterY = 250;
const pulleyX = 220;
const h = waterY - shoreY; // height in pixels

// Angle phi in degrees, then convert to radians
const angleDeg = 30;
const angleRad = angleDeg * Math.PI / 180;

// Calculate boat position based on h and angle
const boatX = pulleyX + h / Math.tan(angleRad);
const boatY = waterY;

// --- Drawing Functions ---
function drawLine(x1, y1, x2, y2) {
    ctx.beginPath();
    ctx.moveTo(x1, y1);
    ctx.lineTo(x2, y2);
    ctx.stroke();
}

// --- Draw Scene Components ---

// 1. Shore (pier)
drawLine(50, shoreY, pulleyX, shoreY); // Horizontal shore line
drawLine(pulleyX, shoreY, pulleyX, waterY); // Vertical pier line

// 2. Water Surface
drawLine(50, waterY, 520, waterY);

// 3. Pulley
ctx.beginPath();
ctx.arc(pulleyX, shoreY, 6, 0, 2 * Math.PI);
ctx.fillStyle = 'white';
ctx.fill();
ctx.stroke();
ctx.fillStyle = 'black';

// 4. Boat
ctx.beginPath();
ctx.arc(boatX, boatY, 7, 0, 2 * Math.PI);
ctx.fill();

// 5. Rope
drawLine(pulleyX, shoreY, boatX, boatY);

// 6. Person
const personX = pulleyX - 80;
const personHeight = 35;
const personHeadRadius = 7;
// Sled/Seat
drawLine(personX - 15, shoreY, personX + 25, shoreY);
// Body
drawLine(personX, shoreY, personX, shoreY - personHeight);
// Head
ctx.beginPath();
ctx.arc(personX, shoreY - personHeight - personHeadRadius, personHeadRadius, 0, 2 * Math.PI);
ctx.stroke();

// --- Draw Labels and Annotations ---

// 7. Velocity/Acceleration Arrow (v, a)
const arrowY = shoreY - personHeight - 30;
const arrowStartX = personX + 30;
const arrowEndX = personX - 50;
ctx.beginPath();
ctx.moveTo(arrowStartX, arrowY);
ctx.lineTo(arrowEndX, arrowY);
ctx.lineTo(arrowEndX + 10, arrowY - 5);
ctx.moveTo(arrowEndX, arrowY);
ctx.lineTo(arrowEndX + 10, arrowY + 5);
ctx.stroke();
ctx.fillText('v, a', personX - 30, arrowY - 8);

// 8. Height Label (h)
ctx.textAlign = 'left';
ctx.fillText('h', pulleyX + 15, shoreY + h / 2 + 5);

// 9. Angle Label (φ)
const arcRadius = 40;
ctx.beginPath();
ctx.arc(boatX, boatY, arcRadius, Math.PI, Math.PI + angleRad);
ctx.stroke();
ctx.textAlign = 'center';
ctx.fillText('φ', boatX - 45, boatY - 10);

// 10. Text Labels (Chinese)
ctx.font = '24px KaiTi, serif';
ctx.textAlign = 'center';
ctx.fillText('水面', pulleyX + 80, waterY + 35);
ctx.textAlign = 'left';
ctx.fillText('船', boatX + 15, boatY + 8);

</script>

</body>
</html>